home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Tool Chest / Development Tools & Languages / HyperCard Related / APDA HyperCard Toolkits / HyperCard Video Toolkit 2.0 / HVT #2 / Advanced Material / Video Sources / vidDrvrS1500.p < prev    next >
Encoding:
Text File  |  1995-02-07  |  15.5 KB  |  556 lines  |  [TEXT/MPS ]

  1. (*
  2.     vidDrvrS1500(cmd,parameters) -- Driver for the Sony 1500 videodisc player. The cmd parameter specifies the
  3.         function to be performed (p1 is the first parameter after cmd; p2 is the second, etc.):
  4.  
  5.                     Command        Function
  6.                     ---------        --------
  7.                     chapter            Return the chapter currently being displayed.
  8.                     control            Execute a series of control functions. Each addition parameter is a keyword to be
  9.                                         executed. If the keyword doesn't make sense here, pass it on to configureSPort.
  10.                                         The following keywords are understood by the video driver:
  11.                                                     Keyword                        Function
  12.                                                     --------                        --------
  13.                                                     init or reset                    Reset the player, configure the serial port (the baud rate is set to
  14.                                                                                         the highest available for the selected player).
  15.                                                     eject or reject                Eject the disc from the player.
  16.                                                     audioOff                        Turn off both audio channels.
  17.                                                     audio1On                        Turn on audio channel 1.
  18.                                                     audio2On                        Turn on audio channel 2.
  19.                                                     stereoOn                        Turn on both audio channels.
  20.                                                     pictureOn/pictureOff    Turn on/off the picture.
  21.                                                     framesOn/framesOff    Turn on/off the display of frame numbers.
  22.                                                     frameMode                    Set player to frame number mode.
  23.                                                     chapterMode                    Set player to chapter number mode.
  24.                                                     timeMode                        Set player to time mode.
  25.                                                     defaultComm                    Set default communications settings for this player.
  26.                     extended        Execute a function specific to the player. This player doesn't have any (yet).
  27.                     fps                Set the frames per second for the next playVideo command to p1, which can be a number or
  28.                                         one of "slowest", "slower", "slow", "normal", "fast", "faster", "fastest".
  29.                     frame            Return the current frame number.
  30.                     name            Return the long name of the player.
  31.                     play                Start a sequence playing, from p1 to p2, which are frame numbers, chapter numbers, or times,
  32.                                         depending upon the mode.
  33.                     scan                Scan forward or backward, depending upong whether p1 is "forward" or "backward".
  34.                     search            Search to frame, chapter, or time p1.
  35.                     sendCmd        Send command p1 to the player and wait for an acknowlege.
  36.                     speeds            Return the frames per second speeds allowed with this player.
  37.                     status            Return the status of the play, which is a comma-separated list containing:
  38.                                                         Keyword                                            Meaning
  39.                                                         --------                                            --------
  40.                                                         doorOpen or park or still or play        State of player.
  41.                                                         CLV or CAV                                        Type of disc.
  42.                                                         disc12inch or disc8inch                        Size of disc being played.
  43.                                                         side1 or side2                                    Side of disc being played.
  44.                     step                Step p1 frames forward (or backward if it's negative), and do it p2 times.
  45.                     time                Return the time of the frame currently being displayed, in 1/60ths of a second since the start
  46.                                         of the disc.
  47.                     version            Return the version of this player driver.
  48.  
  49.     To compile and link this file using Macintosh Programmer's Workshop,
  50.  
  51.         pascal -w vidDrvrS1500.p
  52.         link -m ENTRYPOINT -o HyperCommands -rt XFCN=8032 -sn Main=vidDrvrS1500 ∂
  53.             vidDrvrS1500.p.o "{MPW}"Libraries:interface.o "{MPW}"PLibraries:PasLib.o
  54.  
  55.     Copyright © 1988 Apple Computer, Inc.
  56.  
  57.     2/88 - Initial coding by Harry R. Chesley.
  58. *)
  59.  
  60. {$R-}
  61.  
  62. {$S vidDrvrS1500 }     { Segment name must be the same as the command name. }
  63.  
  64. unit DummyUnit;
  65.  
  66. interface
  67.  
  68. uses MemTypes, QuickDraw, OSIntf, ToolIntf, HyperXCmd;
  69.  
  70. procedure EntryPoint(paramPtr: XCmdPtr);
  71.     
  72. implementation
  73.  
  74. type
  75.  
  76. Str31 = String[31];
  77.  
  78. procedure vidDrvrS1500(paramPtr: XCmdPtr); forward;
  79.  
  80. procedure EntryPoint(paramPtr: XCmdPtr);
  81.  
  82.     begin
  83.         vidDrvrS1500(paramPtr);
  84.     end;
  85.  
  86. procedure vidDrvrS1500(paramPtr: XCmdPtr);
  87.  
  88.     var returnValue: str255;
  89.         pCount: integer;
  90.         p1, p2: str255;
  91.         str: str255;
  92.         i: integer;
  93.         inChapterMode: boolean;
  94.  
  95.     {$I XCmdGlue.inc}
  96.  
  97.     procedure Fail(errMsg: Str255); { set theResult and quit }
  98.         begin
  99.             paramPtr^.returnValue := PasToZero(errMsg);
  100.             exit(vidDrvrS1500);
  101.         end;
  102.  
  103.     {$I VideoUtil.inc}
  104.  
  105.     procedure sendCmd(theCommand: str255);
  106.         { Send a command to the player, waiting for the ack. If noReset is empty,
  107.             then send a reset first. }
  108.  
  109.         var i: integer;
  110.  
  111.         begin
  112.             for i := 1 to length(theCommand) do
  113.                 begin
  114.                     SendCardMessage(Concat('sendSPort "',Copy(theCommand,i,1),'"'));
  115.                     EvalAndDispose('RecvUpTo(numToChar(10),600,empty)');
  116.                 end;
  117.         end;
  118.  
  119.     function frame: str255;
  120.         { Return the current frame number. }
  121.  
  122.         var str: str255;
  123.             endTick: longInt;
  124.  
  125.         begin
  126.             { Get the current frame number... }
  127.             SendCardMessage('sendSPort "`"');
  128.             str := '';
  129.             endTick := TickCount+120;
  130.             repeat
  131.                 str := EvalStr(Concat('recvUpTo(empty,0,"',str,'")'));
  132.                 if length(str) = 1 then
  133.                     if str[1] = chr(11) then
  134.                         begin
  135.                             frame := 'noDisc';
  136.                             exit(frame);
  137.                         end;
  138.             until (length(str) >= 5) or (TickCount > endTick);
  139.             if length(str) < 5 then frame := 'noAnswer'
  140.             else frame := str;
  141.         end;
  142.  
  143.     function chapter: str255;
  144.         { Return the current chapter number. }
  145.  
  146.         var str: str255;
  147.             endTick: longInt;
  148.  
  149.         begin
  150.             { Get the current chapter number... }
  151.             SendCardMessage('sendSPort "v"');
  152.             str := '';
  153.             endTick := TickCount+120;
  154.             repeat
  155.                 str := EvalStr(Concat('recvUpTo(empty,0,"',str,'")'));
  156.                 if length(str) = 1 then
  157.                     if str[1] = chr(11) then
  158.                         begin
  159.                             chapter := 'noChapters';
  160.                             exit(chapter);
  161.                         end;
  162.             until (length(str) >= 2) or (TickCount > endTick);
  163.             if length(str) < 2 then chapter := 'noAnswer'
  164.             else chapter := str;
  165.         end;
  166.  
  167.     function time: str255;
  168.         { Return the time of the current frame. }
  169.  
  170.         begin
  171.             time := 'notImplemented';
  172.         end;
  173.  
  174.     procedure search(var toFrame: str255; blankSearch: boolean);
  175.         { Search to a particular frame, blanking on the way if blankSearch is true. }
  176.  
  177.         begin
  178.             if blankSearch then sendCmd('&');
  179.             sendCmd(Concat('C',toFrame,'@'));
  180.             EvalAndDispose('recvUpTo(numToChar(1),600,empty)');
  181.             if blankSearch then sendCmd('''');
  182.         end;
  183.  
  184.     procedure stop;
  185.         { Stop the player. }
  186.  
  187.         begin
  188.             sendCmd('O');
  189.         end;
  190.  
  191.     procedure control(var keywd: str255);
  192.         { Handle a control command. }
  193.  
  194.         type
  195.             audioModes = (off,oneOn,twoOn,stereo);
  196.  
  197.         var numberOfParms: integer;
  198.             i: integer;
  199.             parm: str255;
  200.  
  201.         procedure ejectPlayer;
  202.             { Eject the disc. }
  203.     
  204.             begin
  205.                 { Send the appropriate eject command. }
  206.                 sendCmd('*');
  207.             end;
  208.     
  209.         procedure audio(onOff: audioModes);
  210.             { Set the audio mode. }
  211.     
  212.             begin
  213.                 { Send the appropriate audio channel command. }
  214.                 case onOff of
  215.                         off:
  216.                             begin
  217.                                 sendCmd('G');
  218.                                 sendCmd('I');
  219.                             end;
  220.                         oneOn:
  221.                             begin
  222.                                 sendCmd('F');
  223.                                 sendCmd('I');
  224.                             end;
  225.                         twoOn:
  226.                             begin
  227.                                 sendCmd('G');
  228.                                 sendCmd('H');
  229.                             end;
  230.                         stereo:
  231.                             begin
  232.                                 sendCmd('F');
  233.                                 sendCmd('H');
  234.                             end;
  235.                         end;
  236.             end;
  237.     
  238.         procedure picture(onOff: boolean);
  239.             { Turn on or off the picture. }
  240.     
  241.             begin
  242.                 { Send the appropriate picture command. }
  243.                 if onOff then sendCmd('''')
  244.                 else sendCmd('&');
  245.             end;
  246.     
  247.         procedure frames(onOff: boolean);
  248.             { Turn on or off the frame display. }
  249.     
  250.             begin
  251.                 { Send the appropriate frame display command. }
  252.                 if onOff then sendCmd('P')
  253.                 else sendCmd('Q');
  254.             end;
  255.     
  256.         procedure defaultComm;
  257.             { Set the default communications parameters. }
  258.  
  259.             begin
  260.                 { Set the port configuration. }
  261.                 SendCardMessage('configureSPort baud9600,echoOff,editOff,linefeedOff,stripOff');
  262.             end;
  263.  
  264.         procedure setMode(theMode: str255);
  265.             { Set the frame/chapter/time mode. }
  266.     
  267.             begin
  268.                 SetStrGlobal('videoMode',theMode);
  269.                 if StringEqual(theMode,'chapterMode') then sendCmd('Vi')
  270.                 else if StringEqual(theMode,'timeMode') then sendCmd('VU')
  271.                 else sendCmd('VU');
  272.             end;
  273.     
  274.         procedure initPlayer;
  275.             { Initialize the player. }
  276.     
  277.             begin
  278.                 { Empty out the globals. }
  279.                 SetStrGlobal('videoMode','');
  280.                 SetStrGlobal('blankNextVideo','');
  281.                 SetStrGlobal('videoSpeed','');
  282.     
  283.                 { Send the reset command for this player. }
  284.                 sendCmd('V');
  285.  
  286.                 { Force it to stop. }
  287.                 stop;
  288.  
  289.                 { Reset the player to known defaults. }
  290.                 setMode('');
  291.                 audio(stereo);
  292.                 frames(false);
  293.                 picture(true);
  294.             end;
  295.     
  296.         begin
  297.             if StringEqual(keywd,'init') or StringEqual(keywd,'reset') then initPlayer
  298.             else if StringEqual(keywd,'eject') or StringEqual(keywd,'reject') then ejectPlayer
  299.             else if StringEqual(keywd,'audioOff') then audio(off)
  300.             else if StringEqual(keywd,'audio1On') then audio(oneOn)
  301.             else if StringEqual(keywd,'audio2On') then audio(twoOn)
  302.             else if StringEqual(keywd,'stereoOn') then audio(stereo)
  303.             else if StringEqual(keywd,'pictureOn') then picture(true)
  304.             else if StringEqual(keywd,'pictureOff') then picture(false)
  305.             else if StringEqual(keywd,'framesOn') then frames(true)
  306.             else if StringEqual(keywd,'framesOff') then frames(false)
  307.             else if StringEqual(keywd,'defaultComm') then defaultComm
  308.             else if StringEqual(keywd,'frameMode') then setMode('')
  309.             else if StringEqual(keywd,'chapterMode') then setMode('chapterMode')
  310.             else if StringEqual(keywd,'timeMode') then setMode('timeMode')
  311.             else SendCardMessage(Concat('configureSPort ',keywd));
  312.         end;
  313.  
  314.     function extended(var keywd: str255): str255;
  315.         { Execute an extended command or function. }
  316.  
  317.         begin
  318.             { No extended command for this player. }
  319.         end;
  320.  
  321.     procedure fps(var fpsKeywd: str255);
  322.         { Set the frames per second. }
  323.  
  324.         var speed: str255;
  325.  
  326.         begin
  327.             speed := '';
  328.  
  329.             { Default speed settings are fine, except: }
  330.             if StringEqual(fpsKeywd,'fast') then speed := '90'
  331.             else if StringEqual(fpsKeywd,'fastest') then speed := '90';
  332.  
  333.             { Set it. }
  334.             if speed <> '' then SetStrGlobal('videoSpeed',speed);
  335.         end;
  336.  
  337.     function name: str255;
  338.         { Return the long name of the player. }
  339.  
  340.         begin
  341.             name := 'Sony 1500';
  342.         end;
  343.  
  344.     procedure play(var firstFrame,lastFrame,speed: str255; blankSearch, chapterMode: boolean);
  345.         { Play a segment. }
  346.  
  347.         var lastFrameNum: longInt;
  348.             startHere: boolean;
  349.             playToLast: boolean;
  350.             fpsNum: longInt;
  351.             rev: boolean;
  352.  
  353.         begin
  354.             { Figure out if we're playing to special (non-numeric markers). }
  355.             startHere := StringEqual(firstFrame,'here');
  356.             playToLast := StringEqual(lastFrame,'lastFrame');
  357.             if playToLast then
  358.                 begin
  359.                     if chapterMode then
  360.                         begin
  361.                             lastFrame := '99';
  362.                             lastFrameNum := 99;
  363.                         end
  364.                     else
  365.                         begin
  366.                             lastFrame := '54000';
  367.                             lastFrameNum := 54000;
  368.                         end;
  369.                 end
  370.             else lastFrameNum := StrToLong(lastFrame);
  371.             fpsNum := StrToLong(speed);
  372.  
  373.             { Figure out whether we're playing forward or reverse. }
  374.             rev := (not playToLast) and
  375.                         (((not startHere) and (lastFrameNum < StrToLong(firstFrame))) or (lastFrameNum = 0));
  376.  
  377.             { Go to the first frame. }
  378.             if (not startHere) and ((not chapterMode) or playToLast or (lastFrameNum = 0)) then
  379.                 search(firstFrame,blankSearch);
  380.             { Play it. }
  381.             if playToLast and (fpsNum = 30) then sendCmd(':')
  382.             else if (lastFrameNum = 0) and (fpsNum = 30) then sendCmd('J')
  383.             else
  384.                 begin
  385.                     if (not playToLast) and (lastFrameNum <> 0) and ((fpsNum = 30) or (not chapterMode)) then
  386.                         begin
  387.                             sendCmd('D');
  388.                             if not playToLast then
  389.                                 begin
  390.                                     if chapterMode then sendCmd(Concat(LongToStr(lastFrameNum-1),'@01@'))
  391.                                     else sendCmd(Concat(lastFrame,'@01@'));
  392.                                 end
  393.                             else sendCmd('@01@');
  394.                         end;
  395.                     if fpsNum > 30 then
  396.                         begin
  397.                             if rev then sendCmd('K')
  398.                             else sendCmd(';');
  399.                         end
  400.                     else if fpsNum < 30 then
  401.                         begin
  402.                             if rev then sendCmd('M')
  403.                             else sendCmd('=');
  404.                             if fpsNum = 15 then sendCmd('2@')
  405.                             else if fpsNum = 10 then sendCmd('3@')
  406.                             else if fpsNum = 3 then sendCmd('10@')
  407.                             else sendCmd('30@');
  408.                         end;
  409.                 end;
  410.         end;
  411.  
  412.     function scan(scanForward: boolean): str255;
  413.         { Scan forward (if scanForward is true), or backward. }
  414.  
  415.         begin
  416.             if scanForward then sendCmd('>')
  417.             else sendCmd('N');
  418.             scan := 'only once';
  419.         end;
  420.  
  421.     procedure step(goForward: boolean);
  422.         { Step one frame forward (if goForward is true) or backward. }
  423.  
  424.         begin
  425.             if goForward then SendCmd('=O')
  426.             else SendCmd('MO');
  427.         end;
  428.  
  429.     function speeds: str255;
  430.         { Return the valid speeds for this player. }
  431.  
  432.         begin
  433.             speeds := '1,3,10,15,30,90';
  434.         end;
  435.  
  436.     function status: str255;
  437.         { Return the current status of the player. }
  438.  
  439.         var str3, str5: str255;
  440.             endTick: longInt;
  441.             charCount: integer;
  442.             theResult: str255;
  443.  
  444.         begin
  445.             { Clear out any pending input. }
  446.             EvalAndDispose('recvUpTo(empty,0,empty)');
  447.     
  448.             { Get the current frame number... }
  449.             SendCardMessage('sendSPort "g"');
  450.             endTick := TickCount+120;
  451.             repeat charCount := StrToLong(Evalstr('charsAvailable()'));
  452.             until (charCount >= 5) or (TickCount > endTick);
  453.             { If we got something... }
  454.             if charCount >= 5 then
  455.                 begin
  456.                     { str3 := character three. }
  457.                     EvalAndDispose('recvChars(2)');
  458.                     str3 := EvalStr('recvChars(1)');
  459.                     if length(str3) = 0 then
  460.                         begin
  461.                             str3[0] := chr(1); str3[1] := chr(0);
  462.                         end;
  463.                     { str5 := character five. }
  464.                     EvalAndDispose('recvChars(1)');
  465.                     str5 := EvalStr('recvChars(1)');
  466.                     if length(str5) = 0 then
  467.                         begin
  468.                             str5[0] := chr(1); str5[1] := chr(0);
  469.                         end;
  470.                     { Figure out the current status. }
  471.                     if BitAnd(ord(str5[1]),127) = 0 then theResult := 'park,'
  472.                     else if BitAnd(ord(str5[1]),96) <> 0 then theResult := 'still,'
  473.                     else theResult := 'play,';
  474.                     if BitAnd(ord(str3[1]),32) <> 0 then theResult := Concat(theResult,'CLV,')
  475.                     else theResult := Concat(theResult,'CAV,');
  476.                     if BitAnd(ord(str3[1]),16) <> 0 then theResult := Concat(theResult,'disc12inch')
  477.                     else theResult := Concat(theResult,'disc8inch');
  478.                     status := theResult;
  479.                 end
  480.             else status := 'noAnswer';
  481.         end;
  482.  
  483.     function version: str255;
  484.         { Return the version of the player driver. }
  485.  
  486.         begin
  487.             version := 'S1500 1.2';
  488.         end;
  489.  
  490.     begin
  491.         pCount := paramPtr^.paramCount;
  492.  
  493.         if pCount <= 0 then Fail('parameter count is not > 0');
  494.  
  495.         if pCount > 1 then GetStrParm(2,p1)
  496.         else p1 := '';
  497.         if pCount > 2 then GetStrParm(3,p2)
  498.         else p2 := '';
  499.  
  500.         GetStrParm(1,str);
  501.  
  502.         returnValue := '';
  503.  
  504.         if StringEqual(str,'chapter') then returnValue := chapter
  505.         else if StringEqual(str,'control') then
  506.             begin
  507.                 for i := 2 to pCount do
  508.                     begin
  509.                         GetStrParm(i,str);
  510.                         control(str);
  511.                     end;
  512.             end
  513.         else if StringEqual(str,'extended') then returnValue := extended(p1)
  514.         else if StringEqual(str,'fps') then fps(p1)
  515.         else if StringEqual(str,'frame') then returnValue := frame
  516.         else if StringEqual(str,'name') then returnValue := name
  517.         else if StringEqual(str,'play') then
  518.             begin
  519.                 GetStrGlobal('videoMode',str);
  520.                 inChapterMode := StringEqual(str,'chapterMode');
  521.                 GetStrGlobal('blankNextVideo',str);
  522.                 if str = '' then
  523.                     begin
  524.                         GetStrGlobal('videoSpeed',str);
  525.                         play(p1,p2,str,false,inChapterMode);
  526.                     end
  527.                 else
  528.                     begin
  529.                         GetStrGlobal('videoSpeed',str);
  530.                         play(p1,p2,str,true,inChapterMode);
  531.                     end;
  532.             end
  533.         else if StringEqual(str,'scan') then
  534.             begin
  535.                 if length(p1) < 1 then returnValue := scan(true)
  536.                 else returnValue := scan(not ((p1[1] = 'b') or (p1[1] = 'B')));
  537.             end
  538.         else if StringEqual(str,'search') then
  539.             begin
  540.                 GetStrGlobal('blankNextVideo',str);
  541.                 search(p1,str <> '');
  542.             end
  543.         else if StringEqual(str,'sendCmd') then sendCmd(p1)
  544.         else if StringEqual(str,'step') then step(p1 = '1')
  545.         else if StringEqual(str,'speeds') then returnValue := speeds
  546.         else if StringEqual(str,'status') then returnValue := status
  547.         else if StringEqual(str,'stop') then stop
  548.         else if StringEqual(str,'time') then returnValue := time
  549.         else if StringEqual(str,'version') then returnValue := version;
  550.  
  551.         { Return the result (if any). }
  552.         paramPtr^.returnValue := PasToZero(returnValue)
  553.     end;
  554.  
  555. end.
  556.